/**
 * Final step, Jsl ready
 */
(function() {

var
	w  = window,
	ol = w.onload,
	d  = document,
	Hp = HTMLElement.prototype
;

/**
 * On ready event
 */
Jsl.onReady = function( cb) {
	if (cb && Jsl.isFunction( cb)) {
		var rf = Jsl.onReady;
		rf.stack[rf.stack.length] = cb;
	}
};
Jsl.onReady.stack = [];

/**
 * On-ready eventhandler
 */
Jsl.ready = window.onload = function() {
	/**
	 * IE version < 8 stuff
	 */
	if (Jsl.isIe && !Jsl.isIe8) {
		Jsl.each( d.all, function( el) {
			Jsl.applyIf( el, Hp);
		});
		Jsl.applyIf( d.body, Hp);
	}

	/**
	 * Registering Jsl Classes and Singletons
	 * into a global scope
	 */
	for (var i in Jsl) {
		if (Jsl.isFunction( Jsl[i]) || typeof Jsl[i] == 'object') {
			var code = Jsl[i].toString(),
				regx = new RegExp( '(' + i + '\\.\\$?super(class)?\\.|\\[object\\s+Jsl\\.)')
			;
			if (regx.test( code)) {
				window[i] = Jsl[i];
			}
		}
	}

	/**
	 * Call the original method
	 */
	Jsl.isFunction( ol) && ol.apply( this, arguments);
	for (var i = 0, s = Jsl.onReady.stack.length; i < s; i++) {
		var f = Jsl.onReady.stack[i];
		f && Jsl.isFunction( f) && f();
	}
};

if (!w.keepSizzle) {
	w.Sizzle     = undefined; // remove Sizzle engine from global scope
	w.keepSizzle = undefined; // remove the keep flag
}

})();
